Repository navigation
Conversation
zcbenz
marked this pull request as ready for review
November 22, 2026 23:45
zcbenz
force-pushed
the
fix/4739-cpu-segmented-mm-half
branch
from
November 22, 2026 23:45
3ec5f01 to
6ac4a0a
Compare
zcbenz
force-pushed
the
fix/4739-cpu-segmented-mm-half
branch
from
November 23, 2026 01:36
6ac4a0a to
4f4b3b1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
☑️ I understand it is strictly prohibited to use AI to write PR description
AI usage disclosure:
Fixes CPU segmented_mm gives wrong values for bfloat16 and float16 #4739.
Summary
matmul_bnns(mlx/backend/cpu/gemms/bnns.cpp),BNNSNDArrayDescriptor::sizeforBNNSDataLayoutRowMajorMatrixwas set to{lda, (M * K) / lda}and{ldb, (K * N) / ldb}instead of the actual logical matrix dimensions{cols, rows}.segmented_mm(or any strided slice) invokesmatmul<float16_t>/matmul<bfloat16_t>withK < ldaorN < ldb,(M * K) / ldatruncates to the wrongrow count (or
0) and reads with the wrong column extent, producing incorrect results.iA_desc.sizeto{a_transposed ? M : K, a_transposed ? K : M},iB_desc.sizeto{b_transposed ? K : N, b_transposed ? N : K}, ando_desc.strideto{1, ldc}while keeping{1, lda}/{1, ldb}as the leading-dimension strides.test segmented_mm float16 and bfloat16intests/blas_tests.cpp) covering all four transpose combinations for bothfloat16andbfloat16.Testing
Built with
-DMLX_BUILD_METAL=OFF -DMLX_BUILD_TESTS=ONon macOS arm64:./build/tests/tests -sf="*blas_tests.cpp": 2/2 test cases passed (31/31 assertions)./build/tests/tests: 277/277 test cases passed (4442/4442 assertions)